define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'bdl/pur/intentionorder/index' + location.search,
                    export_url: 'bdl/pur/intentionorder/export',
                    table: 'pur_intentionorder',
                }
            });

            var table       = $("#table");
            var showExport  = $(".btn-export").data('value')

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                search:false,
                fixedColumns: true,
                fixedRightNumber: 1,
                showToggle: false,
                showExport: showExport,
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: 'ID',operate:false},
                        {
                            field: 'forgid', title: __('数据中心/组织'), searchList: function (column) {
                                return Template('forgidtpl', {});
                            }, formatter: function (value, row, index) {
                                return '无';
                            }, visible: false
                        },
                        // {field: 'fenable', title: '使用状态', searchList: {"1":'可用',"0":'禁用'}, formatter: Table.api.formatter.status},
                        {field: 'fk_bdl_comment', title: '下单备注', operate: 'LIKE'},


                        {field: 'fk_bdl_allqty', title: '总数量',operate:'BETWEEN',  autocomplete:false},


                        {field: 'fk_bdl_wxbillno', title: '小程序定制单号', operate: 'LIKE'},

                        {field: 'fk_bdl_orderstatus', title: '订单状态', searchList: {"1":'待确认',"2":'已确认'}, formatter: Table.api.formatter.status},
                        {field: 'fk_bdl_ordertype', title: '订单类型', searchList: {"1":'期货',"2":'现货'}, formatter: Table.api.formatter.status},
                        {field: 'fk_bdl_image', title: '附件', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'wxuser.fk_bdl_truename', title: '下单用户', operate: 'LIKE'},
                        {field: 'wxuser.id', title: '用户ID', operate: 'LIKE'},
                        {field: 'customer.fname', title: '客户名称', operate: 'LIKE'},
                        {field: 'customer.fnumber', title: '客户编码', operate: 'LIKE'},
                        {field: 'address.bdl_contacts', title: '收货人', operate: 'LIKE'},
                        {field: 'address.fk_bdl_province', title: '收货省', operate: 'LIKE'},
                        {field: 'address.fk_bdl_city', title: '收货市', operate: 'LIKE'},
                        {field: 'address.fk_bdl_region', title: '收货区', operate: 'LIKE'},
                        {field: 'address.fk_bdl_bd_cusaddress', title: '详细地址', operate: 'LIKE'},


                        {field: 'fk_bdl_ordertime', title: '客户下单时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false},


                        {field: 'fk_bdl_allamount', title: '总金额',operate:'BETWEEN',  autocomplete:false},
                        {field: 'fk_bdl_confirmtime', title: '业务员确认时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false},


                        {field: 'datacenter.fname', title: '数据中心名称',operate: false},
                        {field: 'forg.fname', title: '组织名称',operate: false},
                        {field: 'forg.fnumber', title: '组织编码',operate: false},
                        {field: 'forg.id', title: '组织ID',operate: false},


                        {field: 'fk_bdl_createtime', title: '创建时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'fk_bdl_modifytime', title: '修改时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {
                            field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'action',
                                text: '订单信息',
                                icon: 'fa fa-list',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: 'bdl/pur/intentionorder/action'
                            }],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        action: function ()
        {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };

    return Controller;
});
